<?php

namespace app\admin\model;

use think\Model;

class UserAuth extends Model
{
    // 表名
    protected $name = 'user_auth';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text',
        'status_text',
        'uptime_text',
        'audit_time_text'
    ];

    
    public function getTypeList()
    {
        $typeList = [1 => '实名认证'];
        return $typeList;
    }     

    public function getStatusList()
    {
        $statusList = [0 => '未审核',1 => '审核通过',-1 => '审核未通过'];
        return $statusList;
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getUptimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['uptime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAuditTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['audit_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setUptimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setAuditTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
